#Boa:Frame:IncomingRequestFrame

import wx
from request import * 
import logging
from request import *

#get the logger instance for this app
logger = logging.getLogger('provinci')

def create(parent, request):
    return IncomingRequestFrame(parent, request)

[wxID_INCOMINGREQUESTFRAME, wxID_INCOMINGREQUESTFRAMEACCEPTBUTTON, 
 wxID_INCOMINGREQUESTFRAMEDECLINEBUTTON, 
 wxID_INCOMINGREQUESTFRAMEFILESETLISTBOX, wxID_INCOMINGREQUESTFRAMEPANEL1, 
 wxID_INCOMINGREQUESTFRAMESTATICTEXT1, wxID_INCOMINGREQUESTFRAMESTATICTEXT2, 
 wxID_INCOMINGREQUESTFRAMEUSERTEXTCTRL, 
] = [wx.NewId() for _init_ctrls in range(8)]

class IncomingRequestFrame(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_INCOMINGREQUESTFRAME,
              name=u'IncomingRequestFrame', parent=prnt, pos=wx.Point(634, 225),
              size=wx.Size(578, 544), style=wx.DEFAULT_FRAME_STYLE,
              title=u'Incoming request')
        self.SetClientSize(wx.Size(570, 517))

        self.panel1 = wx.Panel(id=wxID_INCOMINGREQUESTFRAMEPANEL1,
              name='panel1', parent=self, pos=wx.Point(0, 0), size=wx.Size(570,
              517), style=wx.TAB_TRAVERSAL)

        self.userTextCtrl = wx.TextCtrl(id=wxID_INCOMINGREQUESTFRAMEUSERTEXTCTRL,
              name=u'userTextCtrl', parent=self.panel1, pos=wx.Point(64, 48),
              size=wx.Size(456, 128), style=wx.TE_MULTILINE, value=u'')
        self.userTextCtrl.SetEditable(False)

        self.acceptButton = wx.Button(id=wxID_INCOMINGREQUESTFRAMEACCEPTBUTTON,
              label=u'Accept...', name=u'acceptButton', parent=self.panel1,
              pos=wx.Point(64, 464), size=wx.Size(75, 23), style=0)
        self.acceptButton.Bind(wx.EVT_LEFT_UP, self.OnAcceptButtonLeftUp)

        self.declineButton = wx.Button(id=wxID_INCOMINGREQUESTFRAMEDECLINEBUTTON,
              label=u'Decline...', name=u'declineButton', parent=self.panel1,
              pos=wx.Point(448, 464), size=wx.Size(75, 23), style=0)
        self.declineButton.Bind(wx.EVT_LEFT_UP, self.OnDeclineButtonLeftUp)

        self.staticText1 = wx.StaticText(id=wxID_INCOMINGREQUESTFRAMESTATICTEXT1,
              label=u'User', name='staticText1', parent=self.panel1,
              pos=wx.Point(72, 32), size=wx.Size(22, 13), style=0)

        self.staticText2 = wx.StaticText(id=wxID_INCOMINGREQUESTFRAMESTATICTEXT2,
              label=u'Requested files', name='staticText2', parent=self.panel1,
              pos=wx.Point(72, 216), size=wx.Size(74, 13), style=0)

        self.filesetListBox = wx.ListBox(choices=[],
              id=wxID_INCOMINGREQUESTFRAMEFILESETLISTBOX,
              name=u'filesetListBox', parent=self.panel1, pos=wx.Point(64, 232),
              size=wx.Size(456, 224), style=0)

    def __init__(self, parent, request):
        self._init_ctrls(parent)
        self.parent = parent
        self.request = request
        self.userTextCtrl.Value = str(request.requester)        
        self.filesetListBox.SetItems([str(fileset) for fileset in request.filesets])
        self.Bind(wx.EVT_LISTBOX_DCLICK, self.filesetListBoxDoubleClick, self.filesetListBox)

    def filesetListBoxDoubleClick(self, event):
        index = self.filesetListBox.GetSelection()
        fileset = self.request.filesets[index]
        dlg = wx.MessageDialog(self, str(fileset), 'File request', wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnAcceptButtonLeftUp(self, event):
        dlg = wx.TextEntryDialog(self, 'Please enter your response', 'Response', 'No comment')
        dlg.SetValue("No comment")
        if dlg.ShowModal() == wx.ID_OK:
            response = Response(self.request.guid, dlg.GetValue())
            self.parent.sendResponse(response)
            self.Close()
        dlg.Destroy()
        
        
        event.Skip()

    def OnDeclineButtonLeftUp(self, event):
        event.Skip()
